package com.rest.demo.concurrent;

import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

/**
 * @author Administrator
 * @decription
 * @Date 2018-01-31 15:34
 */
public class TimeerDemo2 {

    private static int count = 0;

    public static void main(String[] args) {
        class ClockTask extends TimerTask {

            @Override
            public void run() {
                count = (count + 1) % 2;
                System.out.println("--boom--");
                new Timer().schedule(new ClockTask(),2000+2000*count);
            }
        }
        new Timer().schedule(new ClockTask(),2000);

        while(true) {//打印秒钟，一秒输出一次
            System.out.println(new Date().getSeconds());
            try {
                Thread.sleep(1000);
            } catch(Exception e) {
                e.printStackTrace();
            }
        }
    }


}

